export default class MeiQiaUtils {
    private static instance: MeiQiaUtils;

    public static getInstance() {
        if (!this.instance) {
            this.instance = new MeiQiaUtils();
        }
        return this.instance;
    }

    private mMeiQia: ApicloudModules['meiQia'];

    constructor() {
        this.mMeiQia = api.require('meiQia')
        if (!this.mMeiQia) {
            throw new Error('MeiQia 模块没引入')
        }
    }

    public initMeiQia(parmas?: {appkey: string}): Promise<any> {
        return new Promise((res) => {
            this.mMeiQia.initMeiQia(parmas || { appkey: 'e2b24e04bf68c9f1cd67afeac4ec6067' }, (ret) => {
                res(ret)
            })
        })
    }

    public show(params?: {
        showAvatar?: boolean, // 展示用户头像
        showTitle?: boolean, // 展示title
        enableSendVoice?: boolean
        enableSendImage?: boolean, // 聊天页面是否显示发送图片按钮
        enableSendEmoji?: boolean, // 聊天页面是否显示发送表情按钮
        enableCamera?: boolean, // 聊天页面是否显示拍照按钮
        updateClientInfo?: boolean, // 是否更新用户信息，如果为true，在设置过用户信息后可以重新将setClientInfo接口设置的用户信息更新到美洽服务端
    }) {
        this.mMeiQia.show(params)
    }

    public setTitleColor(param?: { color: string }) {
        this.mMeiQia.setTitleColor(param || { color: '#333' })
    }

    public setTitleBarColor(params?: { color: string }) {
        this.mMeiQia.setTitleBarColor(params || { color: '#FFBB00' })
    }

    public setClientInfo(params: { name: string, ID: string, avatar: string }) {
        this.mMeiQia.setClientInfo(params)
    }

    public getUnreadMessageCount(): Promise<number> {
        return new Promise(res => {
            this.mMeiQia.getUnreadMessageCount((ret) => {
                res(ret.count)
            })
        })
    }

    public setLoginCustomizedId(params: {id: string}){
        this.mMeiQia.setLoginCustomizedId(params)
    }
}